
class Person<T> {
	private T age;

	public void setAge(T age){
		this.age =age;
	}

	public T getAge(){
		return this.age;
	}

}

class Student<T>    extends Person <T> {

}

class Student2 extends Person <String> {
}


public class Generics {
	public static void main(String args[]) {
		Person<String> p1 = new Person<String>();
		p1.setAge("3 years old");
	//	System.out.println(p1.getAge());
		printInfo(p1);
		
		Person<Integer> p2 = new Person<Integer>();
		p2.setAge(3);
	//	System.out.println(p2.getAge());
		printInfo(p2);

		Person<?> p3;
		p3 = p1;
		//p3.setAge("4 years old");  //failed
		printInfo(p3);   //setAge failed ,but getAge OK 

		printInfo2(p1);
		printInfo2(p2);
		printInfo2(p3);

		Student<Integer> stu = new Student<Integer>();
		stu.setAge(10);
		printInfo2(stu);
		
		Student2 stu2 = new Student2();
		stu2.setAge("11 years old");
		printInfo(stu2);


		
		
	}

	public static void printInfo(Person<?> p) {
		System.out.println(p.getAge());
	}

	public static <T> void printInfo2(Person<T> p) {
		System.out.println(p.getAge());
	}


	
}








